// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
const eventco = db.collection('event')
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  console.log('evenid 为：'+event.eventid)

  try {
    return await eventco.where({
      _id:event.eventid
    }).remove()
    .then(res=>{
      console.log('删除 event 成功！'+res)
    }).catch(err=>{
      console.log('删除 event 失败！' +err)
    })
  } catch (error) {
    console.log(error)
  }

  return {
    event,
    openid: wxContext.OPENID,
    appid: wxContext.APPID,
    unionid: wxContext.UNIONID,
  }
}